home *** CD-ROM | disk | FTP | other *** search
- {******************************************************************************
- NAME: TEST.ACC
- PURPOSE: To show how a tos application can be converted to
- a desk accessory in Personal Pascal version 1.11.
- Contains many strange but neccessary kludges.
- HISTORY:
- Created: Vitas Povilaitis ( 11/01/87 ) @ Atari Apex BBS (716)458-2638
-
- This program is PUBLIC DOMAIN. Send me no money, but mention my name
- in important circles.
- ******************************************************************************}
- {$A+,D-,S40}
- PROGRAM Test( input, output );
-
- CONST
- {$I gemconst.pas }
- AC_Open = 40; {* accessory opened message value *}
-
- TYPE
- {$I gemtype.pas }
- Screendef = ^Screendata;
- {* The following should be 1..33023 ( 32767 + 256 ),
- however PP v1.11 has a 32K limit *}
- Screendata = PACKED ARRAY[ 1..32766 ] OF CHAR;
-
- VAR
- wind_text : Window_Title; {* title of the window *}
- dummy_window : Integer; {* window to set up the full screen *}
- dummy_menu : Menu_Ptr; {* menu bar to insure desktop redraws menu when
- {* we exit *}
- ap_id : Integer; {* Accessory ID *}
- acc_text : Str255; {* name of this accessory *}
- menu_id : Integer; {* our menu ID *}
- event : INTEGER;
- junk: INTEGER; {* dummy variable for GEM calls *}
- msg : Message_Buffer; {* the message that currently needs to be processed *}
- log_desktop : Screendef;
- phy_desktop : Screendef;
- alt_screen : Screendef;
- dispose_this : Screendef;
-
- {$I GEMSUBS.PAS}
-
- {******************************************************************************
- Main_Register will insert our accessory name into the DESK given our
- application ID number and get our menu_id number as well.
- (Currently, The ST version of GEM never uses the value returned
- by Menu_Register.
- ******************************************************************************}
- FUNCTION Menu_Register( id : INTEGER; VAR name : Str255 ) : INTEGER;
- EXTERNAL;
-
- {******************************************************************************
- Physbase gets the physical screen RAM address
- ******************************************************************************}
- FUNCTION Physbase : Screendef;
- XBIOS( 2 );
-
- {******************************************************************************
- Logbase gets the logical screen RAM base address actually written to
- ******************************************************************************}
- FUNCTION Logbase : Screendef;
- XBIOS( 3 );
-
- {******************************************************************************
- Setscreen sets screen parameters: logical base, physical base, & resolution.
- -1 means no change.
- ******************************************************************************}
- PROCEDURE Setscreen( logbase, phybase : Screendef; rez : INTEGER );
- XBIOS( 5 );
-
- {******************************************************************************
- Alloc_Screen creates the new screen, returns pointer to it.
- ******************************************************************************}
- FUNCTION Alloc_Screen( VAR dispose_this : Screendef ) : Screendef;
-
- CONST
- SCREEN_ADDR_REZ = 256;
-
- VAR
- Scrjunk : RECORD
- CASE BYTE OF
- 0 : ( Sali: Long_Integer );
- 1 : ( Sa : Screendef );
- END;
-
- BEGIN {* Alloc_Screen *}
- WITH Scrjunk DO
- BEGIN
- NEW( Sa );
- dispose_this := Sa;
- IF Sali MOD SCREEN_ADDR_REZ <> 0 THEN
- Sali := Sali + ( SCREEN_ADDR_REZ - ( Sali MOD SCREEN_ADDR_REZ ) );
- END;
- Alloc_Screen := Scrjunk.Sa;
- END; {* Alloc_Screen *}
-
- {******************************************************************************
- Do_Main is the real workhorse since the real main is cluttered with
- initialization routines and the accessory loop.
- ******************************************************************************}
- PROCEDURE Do_Main;
- VAR
- aloop : Integer; {* loop control variable *}
-
- BEGIN {* Do_Main *}
- FOR aloop := 1 TO 90 DO
- WRITELN( aloop, ' : Hello, World!' );
- END; {* Do_Main *}
-
- {*****************************************************************************}
-
- BEGIN {* TEST *}
- ap_id := Init_Gem;
- IF ap_id >= 0 THEN
- BEGIN
- wind_text := ' Window title which will never get printed anyway ';
- acc_text := ' Testing, 1, 2, 3 ';
- menu_id := Menu_Register( ap_id, acc_text );
-
- WHILE TRUE DO {* The main acc loop *}
- BEGIN
- event := Get_Event( E_Message, 0, 0, 0, 0,
- FALSE, 0, 0, 0, 0, FALSE, 0, 0, 0, 0,
- msg, junk, junk, junk, junk, junk, junk );
- {* note that the usage of menu_id has been commented out below *}
- IF ( msg[ 0 ] = AC_Open) {AND msg[ 4 ] = menu_id} THEN
- BEGIN
- dummy_window := New_Window( 0, wind_text, 0, 0, 0, 0 );
- Open_Window( dummy_window, 0, 0, 0, 0 );
- {* I set up an alternate screen for our TOS application
- to preserve the desktop because I have no better way
- to re-draw the menu bar when I return. This is too
- memory hungry so I hope someone comes up with a better
- way to re-draw the menu bar.
- *}
- log_desktop := Logbase;
- phy_desktop := Physbase;
- alt_screen := Alloc_Screen( dispose_this );
- Setscreen( alt_screen, alt_screen, -1 );
- Clear_Screen;
- WRITELN; {* needed or the first line will overwrite the menu bar*}
- Hide_Mouse;
-
- Do_Main; {* our tos application goes here *}
-
- Show_Mouse;
- Setscreen( log_desktop, phy_desktop, -1 );
- DISPOSE( dispose_this );
- Close_Window( dummy_window );
- Delete_Window( dummy_window );
- END; {*IF*}
- END; {*WHILE; The main acc loop*}
- END; {*IF*}
- END. {* TEST *}
-